﻿-- =============================================
-- Author:		GSJ
-- Create date: 2012-6-30
-- Description:	往来收入列表
-- =============================================
CREATE PROCEDURE [dbo].[proc_L_Dealings_GetList]
	(
		@O_CompanyId INT,		
		@StartDate varchar(10),
		@EndDate varchar(10),		
		@StartIndex int,
		@EndIndex int
		
	)
AS
BEGIN
	   ;WITH  list AS(     SELECT ROW_NUMBER() OVER (ORDER BY createdate DESC ) AS Row
           ,id,[O_CompanyId]
           ,[O_CompanyName]
           ,[O_PaymentTypeId]
           ,[O_PaymentTypeName]
           ,[O_BankId]
           ,[O_BankName]
           ,[I_CompanyId]
           ,[I_CompanyName]
           ,[I_PaymentTypeId]
           ,[I_PaymentTypeName]
           ,[I_BankId]
           ,[I_BankName]
           ,[je]
           ,[Agent]
           ,[AgentName]
           ,[PZPerson]
           ,[PZPersonName]
           ,[SHPerson]
           ,[SHPersonName]
           ,[UserId]
           ,[UserName]
           ,[Memo]
           ,CreateDate
           
	FROM  [L_Dealings] WHERE (O_CompanyId=@O_CompanyId OR @O_CompanyId=0) 
	
	AND CONVERT(VARCHAR(10),CreateDate,120) BETWEEN @StartDate AND @EndDate
	   )
	   SELECT * FROM list,(SELECT COUNT(1) AS DataCount,SUM(je) AS DataSum FROM list) AS l1 WHERE row BETWEEN @StartIndex AND @EndIndex
END
